package com.xzzz.common.base;

import com.xzzz.common.base.api.permenv.PermEnvAspect;
import com.xzzz.common.base.log.DynamicLogController;
import com.xzzz.common.base.log.DynamicLogRepository;
import com.xzzz.common.base.log.DynamicLogRepositoryCaffeine;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.logging.LoggingSystem;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * core 模块公共配置
 *
 * @author xzzz
 */
@Configuration
public class BaseConfig {

    @Bean(name = "dynamicLogRepository")
    @ConditionalOnProperty(value = "xzzz.base.log.dynamic-repo", havingValue = "caffeine")
    public DynamicLogRepository dynamicLogRepository(LoggingSystem loggingSystem, BaseProperties properties) {
        return new DynamicLogRepositoryCaffeine(loggingSystem, properties);
    }

    @Bean
    public DynamicLogController dynamicLogController() {
        return new DynamicLogController();
    }

    @Bean
    public PermEnvAspect permEnvAspect() {
        return new PermEnvAspect();
    }
}
